<?php
/**
 * @author: liaofei<136327134@qq.com>
 * @day: 2021/6/4
 */

namespace App\Services\system;

use App\Dao\system\SystemMenusDao;
use App\Services\BaseServices;
use App\Services\system\SystemRoleServices;
use App\Exceptions\ApiException as HOException;
use Hlcreation\Basic\Helper;



/**
 * 权限菜单
 * Class SystemMenusServices
 * @package app\services\system
 * @method save(array $data) 保存数据
 */
class SystemMenusServices extends BaseServices
{

    /**
     * 初始化
     * SystemMenusServices constructor.
     * @param SystemMenusDao $dao
     */
    public function __construct(SystemMenusDao $dao)
    {
        $this->dao = $dao;
    }

    

    /**
     * 获取后台权限菜单和权限
     * @param $rouleId
     * @param int $level
     * @return array
    
     */
    public function getMenusList($adminInfo)
    {
       
        /** @var SystemRoleServices $systemRoleServices */
        $systemRoleServices = app()->make(SystemRoleServices::class);
        
        $rules = $systemRoleServices->getRoleArray(['status' => 1, 'id' => $adminInfo->roles], 'rules');
       
        $rulesStr = Helper::unique($rules);
       
       
        //登录者代理商执行
        if($adminInfo->roles==3){
            //判断用户配置项   去除系统配置项
            if($adminInfo->oem_status==0 && $adminInfo->cloud_status==0 && $adminInfo->sms_status==0){
                 
                $key=array_search(28 ,$rulesStr);
                array_splice($rulesStr,$key,1);
            }
            
        if($adminInfo->oem_status==1)  array_push($rulesStr,49,53);
        
        if($adminInfo->cloud_status==1)  array_push($rulesStr,50,54);
        
        if($adminInfo->sms_status==1)  array_push($rulesStr,51,55);
        }   
        $menusList = $this->dao->getMenusRoule(['route' => $adminInfo->level ? $rulesStr : '']);
        
        $field=['id','pid','icon','menu_name','api_url','is_show_path','menu_path','unique_auth'];
        $unique = $this->dao->getMenusUnique($menusList,['route' => $adminInfo->level ? $rulesStr : ''],$field);
       
        return $unique;
    }

    
   
}
